home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / xlisp / xlsys.c < prev   
Encoding:
C/C++ Source or Header  |  1991-10-04  |  6.5 KB  |  232 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         xlsys.c
  5. * RCS:          $Header: xlsys.c,v 1.7 91/03/24 22:25:38 mayer Exp $
  6. * Description:  xlisp builtin system functions
  7. * Author:       David Michael Betz
  8. * Created:      
  9. * Modified:     Fri Oct  4 04:16:49 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: xlsys.c,v 1.7 91/03/24 22:25:38 mayer Exp $";
  42.  
  43.  
  44. #include "xlisp.h"
  45.  
  46. /* external variables */
  47. extern jmp_buf top_level;
  48. extern FILE *tfp;
  49.  
  50. /* external symbols */
  51. extern LVAL a_subr,a_fsubr,a_cons,a_symbol;
  52. extern LVAL a_fixnum,a_flonum,a_string,a_object,a_stream;
  53. extern LVAL a_vector,a_closure,a_char,a_ustream;
  54. extern LVAL k_verbose,k_print;
  55. extern LVAL true;
  56.  
  57. #if (defined(UNIX) || defined(WINTERP))
  58. extern LVAL a_PIPE;
  59. #endif /* (defined(UNIX) || defined(WINTERP)) */
  60.  
  61. #ifdef WINTERP
  62. extern LVAL a_XtAccelerators, a_XtTranslations, a_XEvent, a_Window, a_Pixel,
  63.   a_Pixmap, a_XImage, a_XmString, a_XmFontList, a_XT_RESOURCE, a_CALLBACKOBJ,
  64.   a_TIMEOUTOBJ, a_PIXMAP_REFOBJ, a_WIDGETOBJ, a_EVHANDLEROBJ;
  65. #endif
  66.  
  67. /* external routines */
  68. extern FILE *osaopen();
  69.  
  70. /* xload - read and evaluate expressions from a file */
  71. LVAL xload()
  72. {
  73.     unsigned char *name;
  74.     int vflag,pflag;
  75.     LVAL arg;
  76.  
  77.     /* get the file name */
  78.     name = getstring(xlgetfname());
  79.  
  80.     /* get the :verbose flag */
  81.     if (xlgetkeyarg(k_verbose,&arg))
  82.     vflag = (arg != NIL);
  83.     else
  84.     vflag = TRUE;
  85.  
  86.     /* get the :print flag */
  87.     if (xlgetkeyarg(k_print,&arg))
  88.     pflag = (arg != NIL);
  89.     else
  90.     pflag = FALSE;
  91.  
  92.     /* load the file */
  93.     return (xlload(name,vflag,pflag) ? true : NIL);
  94. }
  95.  
  96. /* xtranscript - open or close a transcript file */
  97. LVAL xtranscript()
  98. {
  99.     unsigned char *name;
  100.  
  101.     /* get the transcript file name */
  102.     name = (moreargs() ? getstring(xlgetfname()) : NULL);
  103.     xllastarg();
  104.  
  105.     /* close the current transcript */
  106.     if (tfp) osclose(tfp);
  107.  
  108.     /* open the new transcript */
  109.     tfp = (name ? osaopen(name,"w") : NULL);
  110.  
  111.     /* return T if a transcript is open, NIL otherwise */
  112.     return (tfp ? true : NIL);
  113. }
  114.  
  115. /* xtype - return type of a thing */
  116. LVAL xtype()
  117. {
  118.     LVAL arg;
  119.  
  120.     if (!(arg = xlgetarg()))
  121.     return (NIL);
  122.  
  123.     switch (ntype(arg)) {
  124.     case SUBR:        return (a_subr);
  125.     case FSUBR:        return (a_fsubr);
  126.     case CONS:        return (a_cons);
  127.     case SYMBOL:    return (a_symbol);
  128.     case FIXNUM:    return (a_fixnum);
  129.     case FLONUM:    return (a_flonum);
  130.     case STRING:    return (a_string);
  131.     case OBJECT:    return (a_object);
  132.     case STREAM:    return (a_stream);
  133.     case VECTOR:    return (a_vector);
  134.     case CLOSURE:    return (a_closure);
  135.     case CHAR:        return (a_char);
  136.     case USTREAM:    return (a_ustream);
  137.     case STRUCT:    return (getelement(arg,0));
  138. #if (defined(UNIX) || defined(WINTERP))
  139.     case XLTYPE_PIPE:        return (a_PIPE);
  140. #endif /* (defined(UNIX) || defined(WINTERP)) */
  141. #ifdef WINTERP
  142.     case XLTYPE_XtAccelerators: return (a_XtAccelerators);
  143.     case XLTYPE_XtTranslations: return (a_XtTranslations);
  144.     case XLTYPE_XEvent:        return (a_XEvent);
  145.     case XLTYPE_Window:         return (a_Window);
  146.     case XLTYPE_Pixel:          return (a_Pixel);
  147.     case XLTYPE_Pixmap:         return (a_Pixmap);
  148.     case XLTYPE_XImage:         return (a_XImage);
  149.     case XLTYPE_XmString:    return (a_XmString);
  150.     case XLTYPE_XmFontList:     return (a_XmFontList);
  151.     case XLTYPE_XT_RESOURCE:    return (a_XT_RESOURCE);
  152.     case XLTYPE_CALLBACKOBJ:    return (a_CALLBACKOBJ);
  153.     case XLTYPE_TIMEOUTOBJ:     return (a_TIMEOUTOBJ);
  154.     case XLTYPE_PIXMAP_REFOBJ:  return (a_PIXMAP_REFOBJ);
  155.     case XLTYPE_WIDGETOBJ:      return (a_WIDGETOBJ);
  156.     case XLTYPE_EVHANDLEROBJ:   return (a_EVHANDLEROBJ);
  157. #endif
  158.     default:        xlfail("bad node type");
  159.     }
  160. }
  161.  
  162. /* xbaktrace - print the trace back stack */
  163. LVAL xbaktrace()
  164. {
  165.     LVAL num;
  166.     int n;
  167.  
  168.     if (moreargs()) {
  169.     num = xlgafixnum();
  170.     n = getfixnum(num);
  171.     }
  172.     else
  173.     n = -1;
  174.     xllastarg();
  175.     xlbaktrace(n);
  176.     return (NIL);
  177. }
  178.  
  179. /* xexit - get out of xlisp */
  180. LVAL xexit()
  181. {
  182.     xllastarg();
  183.     wrapup();
  184. }
  185.  
  186. /* xpeek - peek at a location in memory */
  187. LVAL xpeek()
  188. {
  189.     LVAL num;
  190.     int *adr;
  191.  
  192.     /* get the address */
  193.     num = xlgafixnum(); adr = (int *)getfixnum(num);
  194.     xllastarg();
  195.  
  196.     /* return the value at that address */
  197.     return (cvfixnum((FIXTYPE)*adr));
  198. }
  199.  
  200. /* xpoke - poke a value into memory */
  201. LVAL xpoke()
  202. {
  203.     LVAL val;
  204.     int *adr;
  205.  
  206.     /* get the address and the new value */
  207.     val = xlgafixnum(); adr = (int *)getfixnum(val);
  208.     val = xlgafixnum();
  209.     xllastarg();
  210.  
  211.     /* store the new value */
  212.     *adr = (int)getfixnum(val);
  213.  
  214.     /* return the new value */
  215.     return (val);
  216. }
  217.  
  218. /* xaddrs - get the address of an XLISP node */
  219. LVAL xaddrs()
  220. {
  221.     LVAL val;
  222.  
  223.     /* get the node */
  224.     val = xlgetarg();
  225.     xllastarg();
  226.  
  227.     /* return the address of the node */
  228.     return (cvfixnum((FIXTYPE)val));
  229. }
  230.  
  231.